package view
{
	import flash.display.Loader;
	import flash.events.*;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.system.LoaderContext;
	import mx.containers.Canvas;
	import mx.containers.TabNavigator;
	import mx.containers.VBox;
	import mx.controls.Alert;
	import mx.controls.Image;
	import mx.controls.TextArea;
	import mx.core.UIComponent;
	public class Info extends UIComponent 
	{
		//public var googleMap:Map;
		//public var point:LatLng;
		//public var mapContainer:UIComponent = new UIComponent();
		public var tabNavigator:TabNavigator = new TabNavigator();
		public var url:String; 
		public var content:String;
		public var urlWeb:String;
		//private var _loader:Loader; 
		public function Info(url:String,urlWeb:String,content:String)
		{
			this.url=url;
			this.content=content;
			this.urlWeb = urlWeb
			tabNavigator.width = 290;
    		tabNavigator.height = 150;
    		tabNavigator.addChild(createPhotoTab("Photo"));
    		
    		tabNavigator.addChild(createInfoTab("Info"));
    		
    		addChild(tabNavigator);
    		cacheAsBitmap = true;
			
		}
		public function createTab(label:String, text:String):VBox {
      		var tab:VBox = new VBox();
      		tab.label = label;
      		var inside:TextArea = new TextArea();
      
      		inside.editable = false;
      		inside.selectable = false;
      		inside.width = 280;
      		inside.height = 100;
      		inside.htmlText = text;
      		inside.setStyle("borderStyle", "none");
      		tab.addChild(inside);
      		return tab;
  		}
  	
  		public function createPhotoTab(label:String):VBox{
  			var can:VBox = new VBox();
  			can.label=label;
  			var inside:Canvas= new Canvas();
  			
  			inside.width = 280;
  			inside.height = 100;
  			var img:Image = new Image();
  			img.x=0;
  			img.y=0;
  			img.width=275;
  			img.height=90;
  			//Alert.show(url);
  			var request:URLRequest = new URLRequest(url);
        	var imageLoader:Loader = new Loader();
        	imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,function(e:Event):void{ 
				img.source = e.currentTarget.content;
 			}); 
  			imageLoader.load(request,new LoaderContext(true));
  			
  			inside.addChild(img);
  			//img.autoLoad=true;
  			can.addChild(inside);
  			return can;
  		}
  		public function createInfoTab(label:String):VBox{
  			var can:VBox = new VBox();
  			can.label=label;
  			var inside:TextArea= new TextArea();
  			
  			inside.editable=false;
  			inside.htmlText="<a href=\"event:os\">"+urlWeb+"</a>"+" <br>"+content;
  			inside.addEventListener(TextEvent.LINK, linkHandler);
  			inside.width = 280;
  			inside.height = 100;
  			inside.setStyle("borderStyle", "none");
  			//inside.text="hello";
  			can.addChild(inside);
  			return can;
  		}
  		private function linkHandler(e:TextEvent):void {
            
             navigateToURL(new URLRequest(urlWeb), "_self");
                    
        }
  		}

	}

